//
//  ProgressView.m
//  OperationQueueDemo
//
//  Created by 苏沫离 on 2018/8/9.
//  Copyright © 2018年 苏沫离. All rights reserved.
//

#import "ProgressView.h"

@implementation ProgressView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self)
    {
        self.layer.cornerRadius = 3;
        self.clipsToBounds = YES;
        self.backgroundColor = [UIColor blackColor];
        
        float progress = 0.56;
        
        CAShapeLayer *progressLayer = [CAShapeLayer layer];
        progressLayer.path = [UIBezierPath bezierPathWithRect:CGRectMake(CGRectGetWidth(frame) * progress, 0, CGRectGetWidth(frame) * (1 - progress), CGRectGetHeight(frame))].CGPath;
        progressLayer.fillColor = [UIColor blueColor].CGColor;
        
        
        CGColorRef color1 = [UIColor redColor].CGColor;
        CGColorRef color2 = [UIColor yellowColor].CGColor;
        
        CAGradientLayer *gradientlayer = [CAGradientLayer layer];
        gradientlayer.frame = self.bounds;
        gradientlayer.colors = @[(__bridge id)color1, (__bridge id)color2];
        gradientlayer.locations = @[@0.33,@0.66];
        gradientlayer.startPoint = CGPointMake(0, 0);
        gradientlayer.endPoint = CGPointMake(1, 0);
        
        [self.layer addSublayer:gradientlayer];
        [self.layer addSublayer:progressLayer];

    }
    return self;
}

@end
